// 2829. k-avoiding 数组的最小总和
// AC: https://leetcode.cn/problems/determine-the-minimum-sum-of-a-k-avoiding-array/submissions/616236449/

class Solution {
public:
    int minimumSum(int n, int k) {
        if(n<=k/2)
            return (1+n)*n/2;
        int sum=(1+(k/2))*(k/2)/2;
        int l=n-(k/2);
        sum+=(l*k+l*(l-1)/2);
        return sum;
    }
};